/**   
* @Title: MarshallingCodeCFactory.java
* @Package com.an.pripro
* @Description: TODO(用一句话描述该文件做什么)
* @author antch,861710865@qq.com   
* @date 2017年8月2日 下午3:19:01
* @version V1.0   
*/

package com.an.pripro;

import org.jboss.marshalling.MarshallerFactory;
import org.jboss.marshalling.Marshalling;
import org.jboss.marshalling.MarshallingConfiguration;

import io.netty.handler.codec.marshalling.DefaultMarshallerProvider;
import io.netty.handler.codec.marshalling.DefaultUnmarshallerProvider;
import io.netty.handler.codec.marshalling.MarshallerProvider;
import io.netty.handler.codec.marshalling.UnmarshallerProvider;

/**
 * @ClassName: MarshallingCodeCFactory
 * @Description: TODO(JBoss Marshalling 是一个Java 对象序列化包,对 JDK 默认的序列化框架进行了优化,<br>
 *               但又保持跟 Java.io.Serializable 接口的兼容,同时增加了一些可调的参数和附件的特性,<br>
 *               这些参数和附加的特性, 这些参数和特性可通过工厂类进行配置. Marshalling 构造工具)
 * @author antch,861710865@qq.com
 * @date 2017年8月2日 下午3:19:01
 * 
 */

public class MarshallingCodeCFactory {

	public static NettyMarshallingDecoder buildMarshallingDecoder() {
		/*
		 * 通过 Marshalling 工具类的 getProvidedMarshallerFactory 静态方法获取MarshallerFactory 实例,
		 * , 参数 serial 表示创建的是 Java 序列化工厂对象.它是由 jboss-marshalling-serial 包提供
		 */

		final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
		final MarshallingConfiguration configuration = new MarshallingConfiguration();
		configuration.setVersion(5);
		UnmarshallerProvider provider = new DefaultUnmarshallerProvider(marshallerFactory, configuration);
		NettyMarshallingDecoder decoder = new NettyMarshallingDecoder(provider, 1024);// 1024 单个对象最大尺寸
		return decoder;
	}

	public static NettyMarshallingEncoder buildMarshallingEncoder() {
		MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
		MarshallingConfiguration configuration = new MarshallingConfiguration();
		configuration.setVersion(5);
		MarshallerProvider provider = new DefaultMarshallerProvider(marshallerFactory, configuration);
		NettyMarshallingEncoder encoder = new NettyMarshallingEncoder(provider);
		return encoder;
	}
}
